package main.java.main;

import com.alibaba.fastjson.JSON;
import main.java.main.bean.AutoBean;
import main.java.main.util.CreateUtil;
import main.java.main.util.DateUtil;

import java.io.IOException;
import java.util.*;

/**
 * 一键生成 所有的api,srv,web端 java/js/xml 文件
 *
 * @author yangsheng
 *
 * @version v1.1.6
 *
 */
public class CreateMainNew {


    public static void main(String[] args) throws IOException {
        // 参数值
        String path = System.getProperty("user.dir") + "/V6NewTools/conf/config.json";
        String jsonStr = CreateUtil.readJsonFile(path);
//        AutoBean bean = null;
        AutoBean bean = JSON.parseObject(jsonStr, AutoBean.class);
        //处理tableListStr
        if(bean.getTableListStr()!=null&&!"".equals(bean.getTableListStr())){
            String[] tableListArr = (bean.getTableListStr()).split(",");
            List<String > tableList = Arrays.asList(tableListArr);
            bean.setTableList(tableList);
        }
        if(bean.getTableListStrDesc()!=null&&!"".equals(bean.getTableListStrDesc())){
            String[] tableListDescArr = (bean.getTableListStrDesc()).split(",");
            List<String > tableList = Arrays.asList(tableListDescArr);
            bean.setTableListDesc(tableList);
        }

        //处理gridListStr
        if(bean.getGridListStr()!=null&&!"".equals(bean.getGridListStr())){
            String[] tableListArr = (bean.getGridListStr()).split(",");
            List<String > tableList = Arrays.asList(tableListArr);
            bean.setGridList(tableList);
        }
        if(bean.getGridListStrDesc()!=null&&!"".equals(bean.getGridListStrDesc())){
            String[] tableListDescArr = (bean.getGridListStrDesc()).split(",");
            List<String > tableList = Arrays.asList(tableListDescArr);
            bean.setGridListDesc(tableList);
        }

        if(bean.getModelFormList()!=null&&bean.getModelFormList().size()>0){
            for(int i=0;i<bean.getModelFormList().size();i++){
                String[] modelFormFeids = (bean.getModelFormList().get(i).getFormFields()).split(",");
                String[] modelFormFeidStrs = (bean.getModelFormList().get(i).getFormFieldStr()).split(",");
                List<String > modelFormFeidList = Arrays.asList(modelFormFeids);
                List<String > modelFormFeidStrList = Arrays.asList(modelFormFeidStrs);
                bean.getModelFormList().get(i).setFormFieldList(modelFormFeidList);
                bean.getModelFormList().get(i).setFormFieldStrList(modelFormFeidStrList);
                System.out.println(bean.getModelFormList().get(i).getFormFieldStrList());
            }
            System.out.println(bean.getModelFormList().get(0).getFormFieldStrList());
        }

        if (bean!=null) {
            bean.setDayTime(DateUtil.currentDate());
            bean.setNumTime(DateUtil.currentDate2());
            try {
                //创建API
                CreateUtil.createApiCode(bean);
                //创建Srv
                CreateUtil.createSrvCode(bean);
                //单独创建detail
//                CreateUtil.createSrvDetailCode(bean);
                //创建Web 代码
                CreateUtil.createWebCode(bean);


                ///test 只输出model
//                CreateUtil.createJsCode(bean);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


}